package org.hot100_6.leetcode1;

import java.util.HashMap;

public class Solution2 {
    public int[] twoSum(int[] nums, int target) {

        int[] res = new int[2];

        int length = nums.length;
        HashMap<Integer, Integer> hashMap = new HashMap<>();


        for (int i = 0; i < length; i++) {
            int num2 = target - nums[i];

            if (hashMap.containsKey(num2)){
                res[0]=i;
                res[1]=hashMap.get(num2);
            }else {
                hashMap.put(nums[i],i);
            }

        }


        return res;
    }
}
